/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sunspotworld;


import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConexionBD{
    
    public Connection c = null;

    public void conectar() throws SQLException{
        
            try {
                DriverManager.registerDriver(new com.mysql.jdbc.Driver());
            } catch (SQLException ex) {
                Logger.getLogger(ConexionBD.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                c = DriverManager.getConnection("jdbc:mysql://localhost/hidroponia","root","");
            } catch (SQLException ex) {
                Logger.getLogger(ConexionBD.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.out.println("Conectado a Hidroponia SQL");
    }

    public ResultSet consultar(String query) throws SQLException{
            ResultSet rs;
            Statement stmt = c.createStatement();
            rs = stmt.executeQuery(query);
            return rs;
    }
    
    public void insertar(String query) throws SQLException{
            Statement stmt = c.createStatement();
            stmt.executeUpdate(query);
    }

    public void desconectar(){
        try {
            c.close();
        } catch (SQLException ex) {
            Logger.getLogger(ConexionBD.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}



   // Broadcast port on which we listen for sensor samples
  /*  private static final int HOST_PORT = 67;
    

    
    private void run() throws Exception {
        RadiogramConnection rCon;
        Radiogram dg;
        try {
            // Open up a server-side broadcast radiogram connection
            // to listen for sensor readings being sent by different SPOTs
            rCon = (RadiogramConnection) Connector.open("radiogram://:" + HOST_PORT);
            dg = (Radiogram)rCon.newDatagram(rCon.getMaximumLength());
        } catch (Exception e) {
             System.err.println("setUp caught " + e.getMessage());
             throw e;
        }

        // Main data collection loop
        while (true) {
            try {
                // Read sensor sample received over the radio
                rCon.receive(dg);
                long time = dg.readLong();      // read time of the reading
                int val = dg.readInt();         // read the sensor value
            } catch (Exception e) {
                System.err.println("Caught " + e +  " while reading sensor samples.");
                throw e;
            }
        }
    } */